package org.jeecg.modules.online.cgform.converter.impl;

import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.converter.FieldCommentConverter;
import org.jeecg.modules.online.cgform.converter.channel.ForeseeConvert;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;

import java.util.ArrayList;
import java.util.List;

/**
 * 字典极简转换模式
 */
public class DictEasyConverter extends ForeseeConvert {

    public DictEasyConverter(OnlCgformField onlCgformField){
        ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class);
        String table = onlCgformField.getDictTable();
        String txt = onlCgformField.getDictText();
        String code = onlCgformField.getDictField();
        List<DictModel> dictList = new ArrayList<DictModel>();
        if(oConvertUtils.isNotEmpty(table)) {
            dictList = sysBaseAPI.queryTableDictItemsByCode(table,txt,code);
        }else if(oConvertUtils.isNotEmpty(code)) {
            dictList = sysBaseAPI.queryDictItemsByCode(code);
        }
        this.dictList = dictList;
        this.filed = onlCgformField.getDbFieldName();
    }

}
